_package("caf.ui");

_import("caf.mui.ListBox");

/**
 * 多个层叠视图的管理组件
 * 每一个Item是延迟加载的和ListBox内的Item工作机制不一样
 */
_class("DeckView", ListBox, function(){
	this._init = function(){
		_super._init.call(this);
		this._itemClass = null;  //{ArticleView}
		//this._hash = {};
		//this._list = [];
		//this._activeItem = null;  //当前活动的视图组件
	};
	this.create = function(parent){
		this.setParent(parent);
		var obj = this.createElement(parent, "div", "wui-DeckView");
		this.init(obj);
		return obj;
	};
	this.bind = function(obj, conf){
		this.setParent(conf.parent);
		this.setId(conf.id);
		//obj.innerHTML = "";
		this.init(obj);
	};
	/**
	 * 重置到初始状态，需要删除所有的视图组件
	 */
	this.reset = function(){
		this._activeItem = null;
		for(var k in this._hash){
			this._hash[k].dispose();
			delete this._hash[k];
		}
	};
	this.dispose = function(){
		/*
		this._activeItem = null;
		for(var i = 0, len = this._list.length; i < len; i++){
			this._list[i] = null;
		}
		this._list = [];
		for(var k in this._hash){
			this._hash[k].dispose();
			delete this._hash[k];
		}
		*/
		this._itemClass = null;
		_super.dispose.apply(this);
	};
	this.setItemClass = function(v){
		this._itemClass = v;
	};
	this.getView = function(id){
		return this.getItem(id);
	};
	this.createView = function(parent, clazz){
		parent = parent || this;
		var clazz = __context__[clazz];
		var view = new clazz();
		view.create(parent);
		this._hash[key] = view;
		return view;
	};
	this.getActiveView = function(){
		return this._activeItem;
	};
	this.activeView = function(v){
		if(this._activeItem == v) return;
		if(this._activeItem){
			this._activeItem.setVisible(false);
		}
		v.setVisible(true);
		this._activeItem = v;
	};
});